package com.sg.business.commons.editingsupport;

import org.eclipse.jface.viewers.ColumnViewer;

import com.sg.business.commons.ui.UIFrameworkUtils;
import com.sg.business.model.Work;
import com.sg.widgets.commons.editingsupport.CellClickListener;
import com.sg.widgets.viewer.CTreeViewer;
import com.sg.widgets.viewer.ViewerControl;

public class EditWorkEditingSupport extends CellClickListener {

	@Override
	protected void selected(Object element, String columnId, ColumnViewer viewer) {
		if (viewer instanceof CTreeViewer) {
			CTreeViewer cTreeViewer = (CTreeViewer) viewer;
			ViewerControl viewerControl = cTreeViewer.getViewerControl();
			if (viewerControl != null) {
				String id = viewerControl.getConfigurator().getId();
				if ("work.wbsndelivery".equals(id)) {
					if (element instanceof Work) {
						UIFrameworkUtils.navigateTo((Work) element,
								UIFrameworkUtils.NAVIGATE_AUTOSELECT, true);
						return;
					}
				}
			}
		}
		super.selected(element, columnId, viewer);
	}

	@Override
	protected void selected(final Object element, String columnId) {
		if (element instanceof Work) {
			Work work = (Work) element;
			if (work.isProjectWBSRoot()) {
				UIFrameworkUtils.navigateToProject(work.getProject());
			} else {
				UIFrameworkUtils.navigateToWork(work);
			}
		}
	}

}
